---
title: custom
description: Creates a custom schema.
source: /schemas/custom/custom.ts
contributors:
  - fabian-hiller
  - EltonLobo07
  - morinokami
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# custom

Creates a custom schema.

> This schema function allows you to define a schema that matches a value based on a custom function. Use it whenever you need to define a schema that cannot be expressed using any of the other schema functions.

```ts
const Schema = v.custom<TInput, TMessage>(check, message);
```

## Generics

- `TInput` <Property {...properties.TInput} />
- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `check` <Property {...properties.check} />
- `message` <Property {...properties.message} />

### Explanation

With `custom` you can validate the data type of the input. If the input does not match the validation of `check`, you can use `message` to customize the error message.

> Make sure that the validation in `check` matches the data type of `TInput`.

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

The following examples show how `custom` can be used.

### Pixel string schema

Schema to validate a pixel string.

```ts
const PixelStringSchema = v.custom<`${number}px`>((input) =>
  typeof input === 'string' ? /^\d+px$/.test(input) : false
);
```

## Related

The following APIs can be combined with `custom`.

### Schemas

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'message',
    'parse',
    'parser',
    'pipe',
    'safeParse',
    'safeParser',
  ]}
/>

### Actions

<ApiList
  items={[
    'args',
    'base64',
    'bic',
    'brand',
    'bytes',
    'check',
    'checkItems',
    'creditCard',
    'cuid2',
    'decimal',
    'description',
    'digits',
    'email',
    'emoji',
    'empty',
    'endsWith',
    'entries',
    'everyItem',
    'excludes',
    'filterItems',
    'findItem',
    'finite',
    'flavor',
    'graphemes',
    'gtValue',
    'hash',
    'hexadecimal',
    'hexColor',
    'imei',
    'includes',
    'integer',
    'ip',
    'ipv4',
    'ipv6',
    'isbn',
    'isoDate',
    'isoDateTime',
    'isoTime',
    'isoTimeSecond',
    'isoTimestamp',
    'isoWeek',
    'length',
    'ltValue',
    'mac',
    'mac48',
    'mac64',
    'mapItems',
    'maxBytes',
    'maxEntries',
    'maxGraphemes',
    'maxLength',
    'maxSize',
    'maxValue',
    'maxWords',
    'metadata',
    'mimeType',
    'minBytes',
    'minEntries',
    'minGraphemes',
    'minLength',
    'minSize',
    'minValue',
    'minWords',
    'multipleOf',
    'nanoid',
    'nonEmpty',
    'notBytes',
    'notEntries',
    'notGraphemes',
    'notLength',
    'notSize',
    'notValue',
    'notValues',
    'notWords',
    'octal',
    'parseJson',
    'partialCheck',
    'rawCheck',
    'rawTransform',
    'readonly',
    'reduceItems',
    'regex',
    'returns',
    'rfcEmail',
    'safeInteger',
    'size',
    'slug',
    'someItem',
    'sortItem',
    'startsWith',
    'stringifyJson',
    'title',
    'toBigint',
    'toBoolean',
    'toDate',
    'toLowerCase',
    'toMaxValue',
    'toMinValue',
    'toNumber',
    'toString',
    'toUpperCase',
    'transform',
    'trim',
    'trimEnd',
    'trimStart',
    'ulid',
    'url',
    'uuid',
    'value',
    'values',
    'words',
  ]}
/>

### Utils

<ApiList items={['entriesFromList', 'isOfKind', 'isOfType']} />
